import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:mandoby/core/app_export.dart';
import 'package:nb_utils/nb_utils.dart';
import 'package:mandoby/core/utils/app_colors.dart';
import 'package:mandoby/features/nationally/presentation/pages/nationally_screen.dart';

class SplashScreen extends StatefulWidget {
  const SplashScreen({Key? key}) : super(key: key);

  @override
  State<SplashScreen> createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> {
  late Timer _timer;

  @override
  void initState() {
    splashConfig();

    super.initState();
  }

  void splashConfig() {
    _timer = Timer.periodic(const Duration(seconds: 3), (timer) {
      NationallyScreen().launch(context,isNewTask: true);
    });
  }

  @override
  void dispose() {
    _timer.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.primary,
      body: Container(
        decoration: AppDecoration.gradientWhiteAToBlue900,
        child: CustomImageView(
          alignment: Alignment.center,
          imagePath: AppAssets.splashLogo,
          color: Colors.white,
        )
            .animate()
            .flip(duration: 750.ms, delay: 500.ms)
            .slideY(duration: 750.ms),
      ),
    );
  }
}
